package com.personnel.controller;

import com.personnel.pojo.ExtraWork;
import com.personnel.service.ExtraWorkService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * (ExtraWork)表控制层
 *
 * @author yuepeng
 * @since 2022-03-04 10:28:31
 * @version 1.0
 */
@RestController
@RequestMapping("/extraWork")
public class ExtraWorkController {
    /**
     * 服务对象
     */
    @Resource
    private ExtraWorkService extraWorkService;

    /**
     * 通过主键查询单条数据
     * @param index  需要查询的页码
     * @param staffName  模糊查询的内容
     * @return 单条数据
     */
    @RequestMapping(value = "/selectForPage", method = RequestMethod.GET)
    public Map<String, Object> selectForPage(@RequestParam(name = "page") int index,int limit, String staffName, Integer status) {
        return this.extraWorkService.selectForPage(index, limit, staffName, status);
    }

    @RequestMapping(value = "/selectCountForTime", method = RequestMethod.GET)
    public Map<String, Object> selectCountForTime(@RequestParam(name = "staffName")String staffName) {
        return this.extraWorkService.selectCountForTime(staffName);
    }

    /**
     * 查询所有数据
     * @return 返回所有数据
     */
    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
    public Map<String, Object> selectAll() {
        return this.extraWorkService.selectAll();
    }

    /**
     * 通过主键删除单条数据
     *
     * @param extraWorkId 主键
     * @return 单条数据
     */
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    public Map<String, Object> deleteById(@RequestParam("extraWorkId") String extraWorkId) {
        return this.extraWorkService.deleteById(extraWorkId);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    public Map<String, Object> selectById(Integer id) {
        return this.extraWorkService.selectById(id);
    }

    /**
     * 通过主键更新单条数据
     *
     * @param extraWork 一个数据库对应的POJO数据对象
     * @return 单条数据
     */
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public Map<String, Object> updateById(@RequestBody ExtraWork extraWork) {
        return this.extraWorkService.updateById(extraWork);
    }

    /**
     * 通过一个pojo对象新增单条数据
     *
     * @param extraWork 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public Map<String, Object> insert(@RequestBody ExtraWork extraWork) {
        return this.extraWorkService.insert(extraWork);
    }

}